#!/usr/bin/env python3

import time

#打印直角形
#  封装以下代码，使以列代码更容易扩展 ?
def triangle(n, flag):
    for i in range(n * n):
        r, c = i // n, i % n
        if (flag == 1 and c >= r)                     \
                or (flag == 2 and c <= r)             \
                or (flag == 3 and c <= n - r - 1)     \
                or (flag == 4 and c >= n - r - 1):
            print('* ', end='')
        else:
            print('  ', end='')
        if c == n - 1:
            print()
    #  if flag == 1:
        #  for i in range(n * n):
            #  r, c = i // n, i % n
            #  ch = '* ' if c >= r else '  '
            #  print(ch, end='')
            #  if c == n - 1:
                #  print()
    #  elif flag == 2:
        #  for i in range(n * n):
            #  r, c = i // n, i % n
            #  ch = '* ' if c <= r else '  '
            #  print(ch, end='')
            #  if c == n - 1:
                #  print()
    #  elif flag == 3:
        #  for i in range(n * n):
            #  r, c = i // n, i % n
            #  ch = '* ' if c <= n - r - 1 else '  '
            #  print(ch, end='')
            #  if c == n - 1:
                #  print()
    #  elif flag == 4:
        #  for i in range(n * n):
            #  r, c = i // n, i % n
            #  ch = '* ' if c >= n - r - 1 else '  '
            #  print(ch, end='')
            #  if c == n - 1:
                #  print()


triangle(5, 1)
triangle(5, 2)
triangle(5, 3)
triangle(5, 4)

exit(0)

c = 1
r = 1
print("\033[?25l")
while True:
    #  i = input()
    #  if i == 'q':
        #  break
    print("\033[2J\033[%d;%dH@" % (r, c), end='', flush=True)
    c += 1
    if c > 79:
        c = 1
        r += 1

    if r > 15:
        r = 1
    time.sleep(0.1)


